
--Global variables
x, y, angle, speed = 400,300,0,10
width, height = 0,0
xvel, yvel = 0,0

--Loaded once in the beginning
function love.load()
    image = love.graphics.newImage("images/bfly.png")
	width = image:getWidth()
	height = image:getHeight()
end


--Draw every frame
function love.draw()
	scale = 0.5
    love.graphics.draw(image, x, y, angle, scale, scale, width/2*scale, height/2*scale)
	love.graphics.print("FPS: " .. love.timer.getFPS(), 50, 50)
	--love.graphics.print("dt: " .. love.timer.getDelta(), 50, 125)
	love.graphics.print("x: " .. x, 50, 65)
	love.graphics.print("y: " .. y, 50, 80)
	love.graphics.print("xvel: " .. xvel, 50, 95)
	love.graphics.print("yvel: " .. yvel, 50, 110)
end

--Update every frame before drawing
function love.update(dt)
	x, y = x + xvel, y - yvel
	if x > (800 + width/2) then
	x = 0 - width/2
	elseif x < - width/2 then
	x = 800 + width/2
	end
	if y > (600+height/2) then
	y = 0 - height/2
	elseif y < 0 - height/2 then
	y = 600 + height/2
	end
	if love.keyboard.isDown("up","w") then
	yvel = yvel + speed * dt
	end
	if love.keyboard.isDown("right","d") then
	xvel = xvel + speed*dt
	end
	if love.keyboard.isDown("left","a") then
	xvel = xvel - speed*dt
	end
	if love.keyboard.isDown("down","s") then
	yvel = yvel - speed*dt
	end
	if love.keyboard.isDown("escape") then
	love.event.push('q')
	end
	if love.keyboard.isDown(" ") then
	xvel = 0 
	yvel = 0
	end
	end